package com.zhengke.service.cggl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhengke.common.dao.CommonDao;
import com.zhengke.common.object.Result;
import com.zhengke.pojo.MallSupplier;
import com.zhengke.pojo.MallSupplierChannel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * *******************************
 * 创建时间：2019/12/31 9:54
 * 项目名称：tvmall-parent
 * 文件名称：null.java
 * 类说明：  采购管理实现类
 *
 * @author 王鑫
 * @version 1.0
 * *******************************
 */
@Service
public class CGGL020ServiceImpl implements CGGL020Service {

    @Autowired
    private CommonDao dao;

    /**
     * 查询供应渠道信息
     * @param channelName
     * @param supplierId
     * @param start
     * @param size
     * @return
     * @throws Exception
     */
    @Override
    public Result queryChannel(String channelName, String supplierId, int start, int size) throws Exception {

        System.out.println("channelName---->"+channelName+"---supplierId---->"+supplierId);
        Map<String, String> param = new HashMap<>();
        param.put("channelName", channelName);
        param.put("supplierId", supplierId);


        PageHelper.startPage(start, size, true);
        List<MallSupplier> rtnList = (List<MallSupplier>) dao.findForList("mallSupplierChannelMapper.query", param);

        System.out.println("cggl020------>>>"+ rtnList);

        PageInfo<MallSupplier> pageInfo = new PageInfo<>(rtnList);

        Result rs = new Result();
        rs.setCode("0");
        rs.setCount(pageInfo.getTotal());
        rs.setData(rtnList);
        return rs;
    }

    /**
     * 	查询供应商
     * @return
     */
    @Override
    public List<MallSupplier> queryMallSupplier() throws Exception {
        List<MallSupplier> msList = (List<MallSupplier>) dao.findForList("mallSupplierChannelMapper.queryMallSupplier", null);
        System.out.println("----->"+msList);
        return msList;
    }

    /**
     * 根据SupplierId 查询当前渠道信息
     * @param channelId
     * @return
     * @throws Exception
     */
    @Override
    public MallSupplierChannel queryMsByChannelId(int channelId) throws Exception {

        MallSupplierChannel mallSupplierChannel = (MallSupplierChannel) dao.findForObject("mallSupplierChannelMapper.queryMsByChannelId",channelId);
        return mallSupplierChannel;
    }


    /**
     * 新增渠道信息
     * @param msc
     * @return
     */
    @Override
    public int save(MallSupplierChannel msc) throws Exception {
        return (Integer) dao.save("mallSupplierChannelMapper.insertSelective",msc);
    }

    /**
     * 修改一条渠道信息
     * @param msc
     */
    @Override
    public int update(MallSupplierChannel msc) throws Exception {
        return (Integer) dao.update("mallSupplierChannelMapper.updateByPrimaryKeySelective",msc);
    }

    /**
     * 删除当前条渠道信息
     * @param channelId
     */
    @Override
    public int delete(int channelId) throws Exception {
        return (Integer) dao.delete("mallSupplierChannelMapper.deleteByPrimaryKey",channelId);

    }
}
